package top.huxy.boot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.huxy.boot.mapper.VideoApiMapper;
import top.huxy.boot.mapper.VideoFeedbackMapper;
import top.huxy.boot.model.dto.DTOVideoFeedback;
import top.huxy.boot.model.entity.VideoApi;
import top.huxy.boot.model.entity.VideoFeedback;
import top.huxy.boot.service.VideoApiService;
import top.huxy.boot.util.RequestUtils;

import java.util.List;

/**
 * @Classname VideoApiServiceImpl
 * @Description VideoApiServiceImpl
 * @Date 2021/9/14 16:55
 * @Created by huxy
 */
@Service
public class VideoApiServiceImpl implements VideoApiService {

    @Autowired
    VideoApiMapper videoApiMapper;

    @Autowired
    VideoFeedbackMapper videoFeedbackMapper;

    @Override
    public List<VideoApi> getVideoApiList() {
        return videoApiMapper.getVideoApiList();
    }

    @Override
    public int add(VideoApi videoApi) {
        return videoApiMapper.add(videoApi);
    }

    @Override
    public int update(VideoApi videoApi) {
        return videoApiMapper.update(videoApi);
    }

    @Override
    public int delete(Integer id) {
        return videoApiMapper.delete(id);
    }

    @Override
    public String feedback(DTOVideoFeedback feedback) {
        feedback.test();

        VideoFeedback videoFeedback = new VideoFeedback();
        videoFeedback.setCreateTime(System.currentTimeMillis());
        videoFeedback.setRate(feedback.getRate());
        videoFeedback.setText(feedback.getText());
        videoFeedback.setRequestId(RequestUtils.getRequestID());
        videoFeedbackMapper.insert(videoFeedback);
        return null;
    }

    @Override
    public int changeEnable(Integer id, Boolean enable) {
        if(enable==null) enable=false;
        return videoApiMapper.changeEnable(id,enable);
    }
}
